package managedbean.SCM.Balance;

import java.io.Serializable;
import javaclass.ProductType;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import session.stateless.SCM.BatchBeanLocal;

@ManagedBean(name = "addProductBalanceManagerBean")
@ViewScoped
public class AddProductBalanceManagerBean implements Serializable{

    public AddProductBalanceManagerBean() {
    }
    
    @EJB
    private BatchBeanLocal batchBeanLocal;
    private ProductType productType;
    private Long balance;
    private String statusMessage;

    public Long getBalance() {
        return balance;
    }

    public void setBalance(Long balance) {
        this.balance = balance;
    }

    public ProductType getProductType() {
        return productType;
    }

    public void setProductType(ProductType productType) {
        this.productType = productType;
    }

    public String getStatusMessage() {
        return statusMessage;
    }

    public void setStatusMessage(String statusMessage) {
        this.statusMessage = statusMessage;
    }
    
    public void saveNewProductBalance(ActionEvent event) {
        
        try 
        {
            boolean success = batchBeanLocal.createProductBalance(productType, balance);
            
            if(!success){
                statusMessage = "Please Try Again.";
                FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Unsuccessful:" + statusMessage + "", ""));
            }else{
                statusMessage = "New Product Balance " + productType + " Saved Successfully.";
                FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, statusMessage, ""));
            }
            
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        
    }
    
}
